package com.qst.survey.util;

import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
 * @Description:FastDFS工具类
 */
@Component
public class FastDFSUtil {

    @Autowired
    FastFileStorageClient storageClient;

    public String uploadFile(MultipartFile file) {
        String fullPath = null;
        try {
            StorePath storePath = storageClient.uploadFile(file.getInputStream(),
                    file.getSize(),
                    StringUtil.substringAfter(file.getOriginalFilename(), '.'),
                    null);
            fullPath = storePath.getFullPath();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return fullPath;
    }


}
